<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>入住支付</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <script type="text/javascript" src="/js/cookie.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form" id="update">
        <div class="layui-form-item">
            <label for="liveId" class="layui-form-label">
                入住编号
            </label>
            <div class="layui-input-inline">
                <input type="" id="liveId" name="liveId" required="" lay-verify="required|number"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="payment" class="layui-form-label">
                支付金额
            </label>
            <div class="layui-input-inline">
                <input type="tel" id="payment" name="payment" required="" lay-verify="required|number"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="payStatus" class="layui-form-label">
                支付状态
            </label>
            <div class="layui-input-inline">
                <select name="payStatus" id="payStatus" class="layui-select-group">
                    <option name="status" value="0">未支付</option>
                    <option name="status" value="1">已支付</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center">
            <button type="button" class="layui-btn" lay-filter="edit" lay-submit="">
                提交支付
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer','laydate'], function () {
        var $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate;

        //获取支付状态
        var selectPayStatus = parent.$("#payStatusValue").val();
        $("#payStatus option[value = " + selectPayStatus + "]").attr("selected", true);
        form.render('select');

        //监听提交
        form.on('submit(edit)', function (data) {
            //发异步，把数据提交给后台
            //获取到表单数据
            //data.field为表单中的数据！
            var sendData=parseParams(data.field);//转换成键值对
            if(data.field.payStatus=="0"){
                layer.alert('请选择已支付状态!',{icon:5});
            }
            else {
                $.ajax({
                    url: '/checkin/edit',
                    type: 'POST',
                    //contentType:"application/json;charset=utf-8",
                    dataType:"json",
                    data: sendData,
                    success: function (res) {
                        //console.log($('#update').serialize());
                        if (res.status == 0) {
                            layer.closeAll('loading');
                            layer.load(2);
                            layer.alert("修改成功", {icon: 6}, function () {
                                console.log(parent);
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                parent.layer.close(index);
                                parent.location.reload();
                            });
                        } else {
                            layer.alert("修改失败", {icon: 5})
                        }
                    },
                })
            }
            return false;
        });

        //解析JSON为urlencode格式
        function parseParams(data) {
            try {
                var tempArr = [];
                for (var i in data) {
                    var key = encodeURIComponent(i);
                    var value = encodeURIComponent(data[i]);
                    tempArr.push(key + '=' + value);
                }
                var urlParamsStr = tempArr.join('&');
                return urlParamsStr;
            } catch (err) {
                return '';
            }
        }
    });
</script>

</body>

</html>